#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>

#define FILENAME "/home/ftl"
#define PROJ_ID 0666
#define SHM_SIZE 4096

#define Debug 0
#define Notice 1
#define Waring 2
#define Error 3

#define fifo "./log.txt"

const char *Mes[] = {
    "Debug",
    "Notice",
    "Waring",
    "Error"};

std::ostream &Log(const std::string &str, size_t mes)
{
    std::cout << " | " << str << " | " << Mes[mes] << " | ";
    return std::cout;
}

class Init
{
public:
    Init()
    {
        int n = mkfifo(fifo, 0666);
        assert(n == 0);
        (void)n;
    }
    ~Init()
    {
        unlink(fifo);
    }
};

int OpenFile(int mode)
{
    int fd = open(fifo, mode);
    assert(fd > 0);
    return fd;
}

void Wait(int fd)
{
    std::cout << "等待中..." << std::endl;
    uint32_t num = 0;
    ssize_t n = read(fd, &num, sizeof(num));
    assert(n == sizeof(num));
    (void)n;
}

void Singal(int fd)
{
    uint32_t num = 1;
    ssize_t n = write(fd, &num, sizeof(num));
    assert(n == sizeof(num));
    (void)n;
    std::cout << "唤醒..." << std::endl;
}